package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.dto.AddWhiteDTO;
import com.sc.nft.entity.dto.WhiteListDTO;
import com.sc.nft.entity.vo.WhiteListVO;
import com.sc.nft.mapper.WorkServiceWhiteMapper;
import com.sc.nft.entity.WorkServiceWhite;
import com.sc.nft.service.WorkServiceWhiteService;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * 城市服务中心和社区白名单考核(WorkServiceWhite)表Dao层
 *
 * @author 王伟成
 * @since 2024-04-08 16:59:46
 */
@Slf4j
@Repository
public class WorkServiceWhiteDao extends ServiceImpl<WorkServiceWhiteMapper, WorkServiceWhite> {

    public WorkServiceWhite getByUserId(Long userId) {
        LambdaQueryWrapper<WorkServiceWhite> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(WorkServiceWhite::getUserId, userId);
        lambdaQuery.last("limit 1");
        return list(lambdaQuery).stream().findFirst().orElse(null);
    }

    /**
     * 白名单列表
     * @param whiteListDTO
     * @return
     */
    public IPage<WhiteListVO> whiteList(WhiteListDTO whiteListDTO) {
        return baseMapper.whiteList(whiteListDTO.toMp(),whiteListDTO);
    }
    public boolean removeByUserId(Long id) {
        LambdaUpdateWrapper<WorkServiceWhite> lambdaUpdate = Wrappers.lambdaUpdate();
        lambdaUpdate.eq(WorkServiceWhite::getUserId, id);
        return remove(lambdaUpdate);
    }

}
